import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'
import { uploadActions } from '../file/upload'
import { downloadActions } from '../file/download'

export const useCounselorStore = defineStore('counselor', {
  state: () => ({
    submitting: false,
    progress: 0,
    lastUpload: null as any | null,
    error: null as string | null,
    // 下载相关状态
    downloading: false,
    downloadProgress: 0,
    downloadError: null as string | null,
    activeDownloadId: null as string | null,
    totalBytes: 0,
    downloadedBytes: 0,
    isPaused: false,
    downloadBuffers: [] as ArrayBuffer[],
    downloadController: null as AbortController | null,
  }),
  actions: {
    // 已移除单请求直传路径，仅保留分片上传

    // 上传/下载相关方法委托至子模块
    ...uploadActions,
    ...downloadActions,
    reset() {
      this.submitting = false
      this.progress = 0
      this.lastUpload = null
      this.error = null
      // 清理下载状态
      this.cancelDownload()
    }
  }
})